package com.n5x.controller;


import com.n5x.service.RedisCacheUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author Administrator
 *
 */
public class SystemConfigInit extends HttpServlet {
	private static Logger logger = Logger.getLogger(SystemConfigInit.class);
	
	/***
	 */
	public void init() throws ServletException {
		try{
			logger.info("system config init start!");
			ServletContext servletContext = getServletContext();
			//初始化加载静态数据
			WebApplicationContext context =  (WebApplicationContext)servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

			//初始化propertise相关数据
			initPropertiesMap();
			logger.info("system config init end!");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * Process the HTTP Get request 
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @throws ServletException
	 * @throws IOException
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException
	{
	}

	/**
	 * Process the HTTP Post request
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @throws ServletException
	 * @throws IOException
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException
	{
		doGet(request, response);
	}

	/**
	 * Clean up resources
	 */
	public void destroy()
	{
	}


	/**
	 * 初始化propertise相关数据
	 */
	private void initPropertiesMap(){
		try {
			WebApplicationContext context =  (WebApplicationContext)getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
			RedisCacheUtil redisCacheUtil = (RedisCacheUtil)context.getBean("redisUtil");
//			redisCacheUtil.getCacheObject("testCache");
			System.out.print("");
		}catch (Exception e){
			e.printStackTrace();
		}
	}

}
